203 閏年判斷
methond 1year = int(input().strip()) if year%400 == 0: print("%d is a leap year." %year) elif year%100 == 0: print("%d is not a leap year." %year) elif year%4 == 0: print("%d is a leap year." %year) else: print("%d is not a leap year." %year)
methond 2
year = int(input().strip()) if year%400==0 or (year%4==0 and year%100!=0): print("%d is a leap year." %year) else: print("%d is not a leap year." %year)
301 迴圈整數連加
a = int(input().strip()) b = int(input().strip()) total=0 if a>b: temp = b b = a a = temp for i in range(a,b+1): total += i print(total)
408 奇偶數個數計算
even=odd=0 for i in range(10): num = int(input().strip()) if num%2 == 0: even += 1 else: odd += 1 print("Even numbers: %d" %even) print("Odd numbers: %d" %odd)
參考資料:TQC+ Python 3